<template>

  <dv-full-screen-container class="container">
    <el-header class="header">
      <div class="header-title">
        <router-link to="/home" style="color: black">
          <div style="font-size: 30px;top: 2000px;">首页</div>
        </router-link>
      </div>
      <div class="header-container">

        <el-menu :default-active="activeIndex" class="el-menu-demo" mode="horizontal" @select="handleSelect">
          <el-submenu index="1">
            <!-- <template slot="title">
              <el-row class="demo-avatar demo-basic">
                <el-col :span="12">
                  <div class="block"><el-avatar :size="38" :src="circleUrl"></el-avatar></div>
                </el-col>
              </el-row>
            </template> -->
            <template slot="title">
              <div class="demo-type">
                <el-avatar
                  src="https://avatars.githubusercontent.com/u/86426294?s=400&u=83f87c5ee72220f3688e6b255820a2ee4f23ec62&v=4.png"
                  @error="errorHandler">
                  <img src="errorPic" />
                </el-avatar>

              </div>
            </template>
            <el-menu-item-group>
              <router-link to="/home/overallDisplay" style="text-decoration: none;color: black">
                <el-menu-item index="1-1">首页</el-menu-item>
              </router-link>


              <div style="text-decoration: none;color: black">
                <el-menu-item index="1-2" type="text" @click="open">切换账号</el-menu-item>
              </div>

              <router-link to="/home/overallDisplay" style="text-decoration: none;color: black">
                <el-menu-item index="1-3" @click="open">退出登录</el-menu-item>
              </router-link>

            </el-menu-item-group>



          </el-submenu>
        </el-menu>
      </div>
    </el-header>

    <el-container>
      <el-aside width="200px" class="aside">
        <!--        tac是左边导航栏-->
        <el-row class="tac">
          <el-col>
            <!--            <h5>导航栏</h5> 下面用空格来调样式-->
            <!---->
            <!-- <h5> </h5> -->
            <el-button @click="toggleCollapse" icon="el-icon-s-tools">{{ isCollapse ? '展开' : '收起' }}</el-button>
            <el-menu default-active="1" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
              :collapse="isCollapse">
              <el-menu-item index="1">
                <i class="el-icon-odometer"></i>
                <router-link to="/home/overallDisplay" style="text-decoration: none;color: black;">
                  <span>仪表盘</span>
                </router-link>
              </el-menu-item>


              <el-submenu index="2">


                <template slot="title">
                  <i class="el-icon-s-goods"></i>
                  <span>商品</span>
                </template>
                <el-menu-item-group>
                  <router-link to="/home/goodsCategory" style="text-decoration: none" v-if="isgoodsCategory">
                    <el-menu-item index="2-1" class="el-icon-goods">&nbsp;商品列表</el-menu-item>
                  </router-link>
                  <router-link to="/home/goodsSort" style="text-decoration: none" v-if="isgoodsSort">
                    <el-menu-item index="2-2" class="el-icon-goods">&nbsp;商品分类</el-menu-item>
                  </router-link>
                </el-menu-item-group>


              </el-submenu>
              <el-submenu index="3">
                <template slot="title">
                  <i class="el-icon-s-custom"></i>
                  <span>权限</span>
                </template>
                <el-menu-item-group>
                  <router-link to="/home/userList" style="text-decoration: none" v-if="isuserList">
                    <el-menu-item index="3-1" class="el-icon-user">&nbsp;用户列表</el-menu-item>
                  </router-link>
                  <router-link to="/home/roleList" style="text-decoration: none" v-if="isroleList">
                    <el-menu-item index="3-2" class="el-icon-user">&nbsp;角色列表</el-menu-item>
                  </router-link>
                </el-menu-item-group>


              </el-submenu>
            </el-menu>
          </el-col>

        </el-row>
      </el-aside>
      <el-main>
        <router-view>

        </router-view>
      </el-main>
    </el-container>
  </dv-full-screen-container>

</template>

<script>
import axios from 'axios';


export default {
  name: 'HomePage',
  data() {
    return {
      isgoodsCategory: true,
      isuserList: true,
      isroleList: true,
      isgoodsSort: true,
      activeIndex: '1',
      activeIndex2: '1',
      circleUrl: "https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png",
      isCollapse: false,
    };
  },
  methods: {
    preventLinkClick(event) {
      event.preventDefault();
      console.log('导航栏被点击，但不会跳转');
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },

    errorHandler() {
      this.errorPic = "https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png";
      return true;
    },
    toggleCollapse() {
      this.isCollapse = !this.isCollapse; // 切换状态
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    open() {
      this.$confirm('即将退出当前帐户', '确认信息', {
        distinguishCancelAndClose: true,
        confirmButtonText: '确认',
        cancelButtonText: '取消'
      })
        .then(() => {
          this.$message({
            type: 'success',
            message: '重新登录',
            duration: 1500
          });
          this.$router.push('/');
        })
        .catch(action => {
          // 用户点击取消，立即提示"取消成功"
          if (action === 'cancel') {
            this.$message({
              type: 'success',
              message: '取消成功',
              duration: 1000 // 设置消息显示时间为2秒
            });
          } else {
            this.$message({
              type: 'success',
              message: '停留在当前页面'
            });
          }
        });
    }
  },
  mounted() {
    const id = JSON.parse(localStorage.getItem('userData')).id
    axios.post('http://localhost:8080/login/getCodeOfUser', { "id": id }).then((res) => {
      console.log(res.data)
      if (res.data == "root")
      {
          this.isgoodsCategory = true;
          this.isuserList = true;
          this.isroleList = true;
          this.isgoodsSort = true;
      }else if(res.data == "test"){
        this.isgoodsCategory = true;
          this.isuserList = false;
          this.isroleList = false;
          this.isgoodsSort = false;
      }else{
        this.isgoodsCategory = true;
          this.isuserList = true;
          this.isroleList = false;
          this.isgoodsSort = false;
      }
    })

  }
}
</script>

<style scoped>
body {
  height: 100vh;
  margin: 0;
  padding: 0;
}

.container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.header-container {
  float: right;

}

.header-title {
  float: left;
  margin-left: 75px;
}

.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}

.router-link-exact-active,
.router-link-active {
  text-decoration: none;
}

.aside {
  padding: 0;
}

router-link {
  text-decoration: none;
}

.el-menu-demo {
  margin-right: 7vh;
}
</style>
